import request from '@/utils/request'

/**
 *
 * @returns  获取员工管理者的信息
 */
export const getEmployeeSimple = () => {
  return request({
    url: '/sys/user/simple'
  })
}

/**
 *
 * @param {object} params {page:页码，size：每页条数}
 * @returns
 */
export const reqGetUserList = (page = 1, size = 5) => {
  return request({
    method: 'get',
    url: '/sys/user',
    params: {
      page,
      size
    }
  })
}

/**
 * 员工删除功能
 * @param {*} id
 * @returns
 */
export function delEmployee(id) {
  return request({
    method: 'delete',
    url: `/sys/user/${id}`
  })
}

/**
 *  新增员工函数
 * @param {object} form
 * @returns
 */
export const reqAddEmployee = (form) => {
  return request({
    method: 'post',
    url: '/sys/user',
    data: form
  })
}

/**
 * 保存员工基本信息
 * @param {*} data
 * @returns
 */
export const SaveUserDetailById = (data) => {
  return request({
    method: 'put',
    url: `/sys/user/${data.id}`,
    data
  })
}

/**
 * 读取用户详情的基础信息
 * @param {*} id  用户id
 * @returns
 */
export const getPersonalDetail = (id) => {
  return request({
    url: `/employees/${id}/personalInfo`
  })
}

/**
 * 更新用户详情的基础信息
 * @param {*} data 员工数据
 * @returns
 */
export const updatePersonal = (data) => {
  return request({
    url: `/employees/${data.userId}/personalInfo`,
    method: 'put',
    data
  })
}

/**
 * 获取用户的岗位信息
 * @param {*} id
 * @returns
 */
export const getJobDetail = (id) => {
  return request({
    url: `/employees/${id}/jobs`
  })
}

/**
 * 保存岗位信息
 * @param {*} data
 * @returns
 */
export const updateJob = (data) => {
  return request({
    url: `/employees/${data.userId}/jobs`,
    method: 'put',
    data
  })
}

/**
 * 批量添加员工
 * @param {*} arr [{}, {}, {}, ...]
 */
export const reqAddEmployeeBatch = (arr) => {
  return request({
    method: 'post',
    url: '/sys/user/batch',
    data: arr
  })
}

/**
 * 给员工分配角色
 * @param {*} id 员工id
 * @param {*} roleIds 角色id数组
 * @returns
 */
export const assignRole = (id, roleIds) => {
  return request({
    method: 'put',
    url: '/sys/user/assignRoles',
    data: {
      id,
      roleIds
    }
  })
}

export const addEmployee = () => {

}
